library(DeclareDesign)
library(rdss)
library(tidyverse)
library(scales)


diagnosis_18.12 <- read_rds("diagnosis_objects/diagnosis_18.12.rds")

simulations <- 
  diagnosis_18.12 |> 
  get_simulations()

inquiry_df <-
  diagnosis_18.12 |> 
  get_diagnosands()

g <-
  ggplot(simulations) +
  aes(estimate) +
  geom_histogram(
    aes(y = ..count.. / sum(..count..)), 
    fill = dd_palette("dd_light_blue_alpha"),
    color = "transparent",
    binwidth = 0.06) +
  geom_vline(
    data = inquiry_df,
    aes(xintercept = mean_estimand),
    linetype = "dashed",
    color = dd_palette("dd_pink")
  ) +
  geom_text(
    data = inquiry_df,
    aes(x = mean_estimand),
    y = 0.09,
    label = "Estimand",
    nudge_x = 0.05,
    hjust = 0,
    color = dd_palette("dd_pink")
  ) + 
  scale_y_continuous(labels = percent_format(accuracy = 1),
                     breaks = seq(0, 0.1, 0.02)) +
  facet_wrap( ~ estimator) +
  theme_dd() + 
  labs(x = "Simulated effect estimate",
       y = "Percent of simulations")

g

ggsave("figures/figure_18.14.pdf",
       g,
       width = 6.5,
       height = 3)
ggsave("figures/figure_18.14.svg",
       g,
       width = 6.5,
       height = 3)
